namespace ts {
    export type ErrorCallback = (message: DiagnosticMessage, length: number) => void;

    /* @internal */
    export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
        return token >= SyntaxKind.Identifier;
    }

    /* @internal */
    export function tokenIsIdentifierOrKeywordOrGreaterThan(token: SyntaxKind): boolean {
        return token === SyntaxKind.GreaterThanToken || tokenIsIdentifierOrKeyword(token);
    }

    export interface Scanner {
        getStartPos(): number;
        getToken(): SyntaxKind;
        getTextPos(): number;
        getTokenPos(): number;
        getTokenText(): string;
        getTokenValue(): string;
        hasUnicodeEscape(): boolean;
        hasExtendedUnicodeEscape(): boolean;
        hasPrecedingLineBreak(): boolean;
        isIdentifier(): boolean;
        isReservedWord(): boolean;
        isUnterminated(): boolean;
        /* @internal */
        getTokenFlags(): TokenFlags;
        reScanGreaterToken(): SyntaxKind;
        reScanSlashToken(): SyntaxKind;
        reScanTemplateToken(): SyntaxKind;
        reScanLessThanToken(): SyntaxKind;
        scanJsDocToken(): JSDocSyntaxKind;
        扫描词典语句令牌(): 转换词典语句令牌_;
        scan(): SyntaxKind;
        getText(): string;
        // Sets the text for the scanner to scan.  An optional subrange starting point and length
        // can be provided to have the scanner only scan a portion of the text.
        setText(text: string | undefined, start?: number, length?: number): void;
        setOnError(onError: ErrorCallback | undefined): void;
        setTextPos(textPos: number): void;
        /* @internal */
        setInJSDocType(inType: boolean): void;
        // Invokes the provided callback then unconditionally restores the scanner to the state it
        // was in immediately prior to invoking the callback.  The result of invoking the callback
        // is returned from this function.
        lookAhead<T>(callback: () => T): T;

        // Invokes the callback with the scanner set to scan the specified range. When the callback
        // returns, the scanner is restored to the state it was in before scanRange was called.
        scanRange<T>(start: number, length: number, callback: () => T): T;

        // Invokes the provided callback.  If the callback returns something falsy, then it restores
        // the scanner to the state it was in immediately prior to invoking the callback.  If the
        // callback returns something truthy, then the scanner state is not rolled back.  The result
        // of invoking the callback is returned from this function.
        tryScan<T>(callback: () => T): T;
    }

    const textToKeywordObj: MapLike<KeywordSyntaxKind> = {
        通用: SyntaxKind.AnyKeyword,
        真假: SyntaxKind.BooleanKeyword,
        跳出: SyntaxKind.BreakKeyword,
        构建: SyntaxKind.构建关键字_,
        释放: SyntaxKind.释放关键字_,
        恒定: SyntaxKind.恒定关键字_,
        只读: SyntaxKind.只读关键字_,
        共享: SyntaxKind.共享关键字_,
        若是: SyntaxKind.CaseKeyword,
        继续: SyntaxKind.ContinueKeyword,
        常量: SyntaxKind.ConstKeyword,
        调试: SyntaxKind.DebuggerKeyword,
        默认: SyntaxKind.DefaultKeyword,
        删除: SyntaxKind.DeleteKeyword,
        否则: SyntaxKind.ElseKeyword,
        枚举: SyntaxKind.EnumKeyword,
        false: SyntaxKind.FalseKeyword,
        假: SyntaxKind.FalseKeyword,
        循环: SyntaxKind.ForKeyword,
        来自: SyntaxKind.FromKeyword,
        函数: SyntaxKind.FunctionKeyword,
        如果: SyntaxKind.IfKeyword,
        导入: SyntaxKind.ImportKeyword,
        接口: SyntaxKind.InterfaceKeyword,
        变量: SyntaxKind.LetKeyword,
        新建: SyntaxKind.NewKeyword,
        空值: SyntaxKind.NullKeyword,
        返回: SyntaxKind.ReturnKeyword,
        文本: SyntaxKind.StringKeyword,
        文本8: SyntaxKind.文本8_,
        文本16: SyntaxKind.文本16_,
        文本32: SyntaxKind.文本32_,
        假如: SyntaxKind.SwitchKeyword,
        本体: SyntaxKind.ThisKeyword,
        基类: SyntaxKind.基类关键字_,
        true: SyntaxKind.TrueKeyword,
        真: SyntaxKind.TrueKeyword,
        类型: SyntaxKind.TypeKeyword,
        未知: SyntaxKind.UnknownKeyword,
        未定: SyntaxKind.未定关键字_,
        指针: SyntaxKind.指针关键字_,
        正量: SyntaxKind.正量关键字_,
        无值: SyntaxKind.VoidKeyword,
        不及: SyntaxKind.不及关键字_,
        属于: SyntaxKind.OfKeyword,
        方法: SyntaxKind.方法关键字_,
        对象: SyntaxKind.对象关键字_,
        结构: SyntaxKind.结构关键字_,
        别名: SyntaxKind.别名关键字_,
        另如: SyntaxKind.另如关键字_,
        延迟: SyntaxKind.延迟关键字_,
        执行: SyntaxKind.执行关键字_,
        程序: SyntaxKind.程序关键字_,
        全局: SyntaxKind.全局关键字_,
        原型: SyntaxKind.原型关键字_,
        启动: SyntaxKind.启动关键字_,
        初始: SyntaxKind.初始关键字_,

        捕获: SyntaxKind.CatchKeyword,
        最终: SyntaxKind.FinallyKeyword,
        尝试: SyntaxKind.TryKeyword,
        抛出: SyntaxKind.ThrowKeyword,

        指令: SyntaxKind.指令关键字_,
        同步: SyntaxKind.同步关键字_,
        测试: SyntaxKind.测试关键字_,
        断言: SyntaxKind.断言关键字_,
        版本: SyntaxKind.版本关键字_,

        整数: SyntaxKind.整数关键字_,
        正整数: SyntaxKind.正整数关键字_,
        整数8: SyntaxKind.整数8_,
        整数16: SyntaxKind.整数16_,
        整数32: SyntaxKind.整数32_,
        整数64: SyntaxKind.整数64_,
        正整数8: SyntaxKind.正整数8_,
        正整数16: SyntaxKind.正整数16_,
        正整数32: SyntaxKind.正整数32_,
        正整数64: SyntaxKind.正整数64_,
        小数: SyntaxKind.小数关键字_,
        小数32: SyntaxKind.小数32_,
        小数64: SyntaxKind.小数64_,
        虚数32: SyntaxKind.虚数32_,
        虚数64: SyntaxKind.虚数64_,
        复数64: SyntaxKind.复数64_,
        复数128: SyntaxKind.复数128_,
        字符: SyntaxKind.字符_,
        字符8: SyntaxKind.字符8_,
        字符16: SyntaxKind.字符16_,
        字符32: SyntaxKind.字符32_,
        字节: SyntaxKind.字节_
    };

    const textToKeyword = createMapFromTemplate(textToKeywordObj);

    const textToToken = createMapFromTemplate<SyntaxKind>({
        ...textToKeywordObj,
        "{": SyntaxKind.OpenBraceToken,
        "}": SyntaxKind.CloseBraceToken,
        "(": SyntaxKind.OpenParenToken,
        ")": SyntaxKind.CloseParenToken,
        "[": SyntaxKind.OpenBracketToken,
        "]": SyntaxKind.CloseBracketToken,
        "·": SyntaxKind.中点号_,
        ".": SyntaxKind.DotToken,
        "...": SyntaxKind.DotDotDotToken,        
        "..": SyntaxKind.DotDotToken,
        ";": SyntaxKind.SemicolonToken,
        ",": SyntaxKind.CommaToken,
        "<": SyntaxKind.LessThanToken,
        ">": SyntaxKind.GreaterThanToken,
        "<=": SyntaxKind.LessThanEqualsToken,
        ">=": SyntaxKind.GreaterThanEqualsToken,
        "==": SyntaxKind.EqualsEqualsToken,
        "!=": SyntaxKind.ExclamationEqualsToken,
        "=>": SyntaxKind.EqualsGreaterThanToken,
        "+": SyntaxKind.PlusToken,
        "-": SyntaxKind.MinusToken,
        "*": SyntaxKind.AsteriskToken,
        "/": SyntaxKind.SlashToken,
        "%": SyntaxKind.PercentToken,
        "++": SyntaxKind.PlusPlusToken,
        "--": SyntaxKind.MinusMinusToken,
        "<<": SyntaxKind.LessThanLessThanToken,
        ">>": SyntaxKind.GreaterThanGreaterThanToken,
        "&": SyntaxKind.AmpersandToken,
        "|": SyntaxKind.BarToken,
        "^": SyntaxKind.CaretToken,
        "!": SyntaxKind.ExclamationToken,
        "~": SyntaxKind.TildeToken,
        "&&": SyntaxKind.AmpersandAmpersandToken,
        "||": SyntaxKind.BarBarToken,
        "?": SyntaxKind.QuestionToken,
        "?.": SyntaxKind.QuestionDotToken,
        ":": SyntaxKind.ColonToken,
        "=": SyntaxKind.EqualsToken,
        "+=": SyntaxKind.PlusEqualsToken,
        "-=": SyntaxKind.MinusEqualsToken,
        "*=": SyntaxKind.AsteriskEqualsToken,
        "/=": SyntaxKind.SlashEqualsToken,
        "%=": SyntaxKind.PercentEqualsToken,
        "<<=": SyntaxKind.LessThanLessThanEqualsToken,
        ">>=": SyntaxKind.GreaterThanGreaterThanEqualsToken,
        ">>>=": SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
        "&=": SyntaxKind.AmpersandEqualsToken,
        "|=": SyntaxKind.BarEqualsToken,
        "^=": SyntaxKind.CaretEqualsToken,
        "@": SyntaxKind.AtToken,
        "`": SyntaxKind.BacktickToken,
        "->": SyntaxKind.MinusGreaterThanToken,
        "<-": SyntaxKind.LessThanMinusToken,
        ":>": SyntaxKind.ColonGreaterThanToken,
        ":=": SyntaxKind.ColonEqualsToken,
        ".<": SyntaxKind.点左尖号_,
        ".(": SyntaxKind.点左括号_,        
        ".[": SyntaxKind.DotOpenBracketToken,
        "//@": SyntaxKind.输出转换词典头_,
        "//#": SyntaxKind.输入转换词典头_
    });

    /**
     * Generated by scripts/regenerate-unicode-identifier-parts.js on node v12.4.0 with unicode 12.1
     * based on http://www.unicode.org/reports/tr31/ and https://www.ecma-international.org/ecma-262/6.0/#sec-names-and-keywords
     * unicodeESNextIdentifierStart corresponds to the ID_Start and Other_ID_Start property, and
     * unicodeESNextIdentifierPart corresponds to ID_Continue, Other_ID_Continue, plus ID_Start and Other_ID_Start
     */
    const unicodeESNextIdentifierStart = [65, 90, 97, 122, 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 895, 895, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1488, 1514, 1519, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2144, 2154, 2208, 2228, 2230, 2237, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2432, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2556, 2556, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2809, 2809, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3133, 3160, 3162, 3168, 3169, 3200, 3200, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3412, 3414, 3423, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6264, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6430, 6480, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7401, 7404, 7406, 7411, 7413, 7414, 7418, 7418, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12443, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42653, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43261, 43262, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43488, 43492, 43494, 43503, 43514, 43518, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43646, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594, 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786, 65856, 65908, 66176, 66204, 66208, 66256, 66304, 66335, 66349, 66378, 66384, 66421, 66432, 66461, 66464, 66499, 66504, 66511, 66513, 66517, 66560, 66717, 66736, 66771, 66776, 66811, 66816, 66855, 66864, 66915, 67072, 67382, 67392, 67413, 67424, 67431, 67584, 67589, 67592, 67592, 67594, 67637, 67639, 67640, 67644, 67644, 67647, 67669, 67680, 67702, 67712, 67742, 67808, 67826, 67828, 67829, 67840, 67861, 67872, 67897, 67968, 68023, 68030, 68031, 68096, 68096, 68112, 68115, 68117, 68119, 68121, 68149, 68192, 68220, 68224, 68252, 68288, 68295, 68297, 68324, 68352, 68405, 68416, 68437, 68448, 68466, 68480, 68497, 68608, 68680, 68736, 68786, 68800, 68850, 68864, 68899, 69376, 69404, 69415, 69415, 69424, 69445, 69600, 69622, 69635, 69687, 69763, 69807, 69840, 69864, 69891, 69926, 69956, 69956, 69968, 70002, 70006, 70006, 70019, 70066, 70081, 70084, 70106, 70106, 70108, 70108, 70144, 70161, 70163, 70187, 70272, 70278, 70280, 70280, 70282, 70285, 70287, 70301, 70303, 70312, 70320, 70366, 70405, 70412, 70415, 70416, 70419, 70440, 70442, 70448, 70450, 70451, 70453, 70457, 70461, 70461, 70480, 70480, 70493, 70497, 70656, 70708, 70727, 70730, 70751, 70751, 70784, 70831, 70852, 70853, 70855, 70855, 71040, 71086, 71128, 71131, 71168, 71215, 71236, 71236, 71296, 71338, 71352, 71352, 71424, 71450, 71680, 71723, 71840, 71903, 71935, 71935, 72096, 72103, 72106, 72144, 72161, 72161, 72163, 72163, 72192, 72192, 72203, 72242, 72250, 72250, 72272, 72272, 72284, 72329, 72349, 72349, 72384, 72440, 72704, 72712, 72714, 72750, 72768, 72768, 72818, 72847, 72960, 72966, 72968, 72969, 72971, 73008, 73030, 73030, 73056, 73061, 73063, 73064, 73066, 73097, 73112, 73112, 73440, 73458, 73728, 74649, 74752, 74862, 74880, 75075, 77824, 78894, 82944, 83526, 92160, 92728, 92736, 92766, 92880, 92909, 92928, 92975, 92992, 92995, 93027, 93047, 93053, 93071, 93760, 93823, 93952, 94026, 94032, 94032, 94099, 94111, 94176, 94177, 94179, 94179, 94208, 100343, 100352, 101106, 110592, 110878, 110928, 110930, 110948, 110951, 110960, 111355, 113664, 113770, 113776, 113788, 113792, 113800, 113808, 113817, 119808, 119892, 119894, 119964, 119966, 119967, 119970, 119970, 119973, 119974, 119977, 119980, 119982, 119993, 119995, 119995, 119997, 120003, 120005, 120069, 120071, 120074, 120077, 120084, 120086, 120092, 120094, 120121, 120123, 120126, 120128, 120132, 120134, 120134, 120138, 120144, 120146, 120485, 120488, 120512, 120514, 120538, 120540, 120570, 120572, 120596, 120598, 120628, 120630, 120654, 120656, 120686, 120688, 120712, 120714, 120744, 120746, 120770, 120772, 120779, 123136, 123180, 123191, 123197, 123214, 123214, 123584, 123627, 124928, 125124, 125184, 125251, 125259, 125259, 126464, 126467, 126469, 126495, 126497, 126498, 126500, 126500, 126503, 126503, 126505, 126514, 126516, 126519, 126521, 126521, 126523, 126523, 126530, 126530, 126535, 126535, 126537, 126537, 126539, 126539, 126541, 126543, 126545, 126546, 126548, 126548, 126551, 126551, 126553, 126553, 126555, 126555, 126557, 126557, 126559, 126559, 126561, 126562, 126564, 126564, 126567, 126570, 126572, 126578, 126580, 126583, 126585, 126588, 126590, 126590, 126592, 126601, 126603, 126619, 126625, 126627, 126629, 126633, 126635, 126651, 131072, 173782, 173824, 177972, 177984, 178205, 178208, 183969, 183984, 191456, 194560, 195101];
    const unicodeESNextIdentifierPart = [48, 57, 65, 90, 95, 95, 97, 122, 170, 170, 181, 181, 182, 182, 184, 184, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 895, 895, 902, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1519, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2045, 2045, 2048, 2093, 2112, 2139, 2144, 2154, 2208, 2228, 2230, 2237, 2259, 2273, 2275, 2403, 2406, 2415, 2417, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2556, 2556, 2558, 2558, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2809, 2815, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3072, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3162, 3168, 3171, 3174, 3183, 3200, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3328, 3331, 3333, 3340, 3342, 3344, 3346, 3396, 3398, 3400, 3402, 3406, 3412, 3415, 3423, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3558, 3567, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4969, 4977, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6264, 6272, 6314, 6320, 6389, 6400, 6430, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6618, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6832, 6845, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7376, 7378, 7380, 7418, 7424, 7673, 7675, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42737, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43047, 43072, 43123, 43136, 43205, 43216, 43225, 43232, 43255, 43259, 43259, 43261, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43488, 43518, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65071, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594, 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786, 65856, 65908, 66045, 66045, 66176, 66204, 66208, 66256, 66272, 66272, 66304, 66335, 66349, 66378, 66384, 66426, 66432, 66461, 66464, 66499, 66504, 66511, 66513, 66517, 66560, 66717, 66720, 66729, 66736, 66771, 66776, 66811, 66816, 66855, 66864, 66915, 67072, 67382, 67392, 67413, 67424, 67431, 67584, 67589, 67592, 67592, 67594, 67637, 67639, 67640, 67644, 67644, 67647, 67669, 67680, 67702, 67712, 67742, 67808, 67826, 67828, 67829, 67840, 67861, 67872, 67897, 67968, 68023, 68030, 68031, 68096, 68099, 68101, 68102, 68108, 68115, 68117, 68119, 68121, 68149, 68152, 68154, 68159, 68159, 68192, 68220, 68224, 68252, 68288, 68295, 68297, 68326, 68352, 68405, 68416, 68437, 68448, 68466, 68480, 68497, 68608, 68680, 68736, 68786, 68800, 68850, 68864, 68903, 68912, 68921, 69376, 69404, 69415, 69415, 69424, 69456, 69600, 69622, 69632, 69702, 69734, 69743, 69759, 69818, 69840, 69864, 69872, 69881, 69888, 69940, 69942, 69951, 69956, 69958, 69968, 70003, 70006, 70006, 70016, 70084, 70089, 70092, 70096, 70106, 70108, 70108, 70144, 70161, 70163, 70199, 70206, 70206, 70272, 70278, 70280, 70280, 70282, 70285, 70287, 70301, 70303, 70312, 70320, 70378, 70384, 70393, 70400, 70403, 70405, 70412, 70415, 70416, 70419, 70440, 70442, 70448, 70450, 70451, 70453, 70457, 70459, 70468, 70471, 70472, 70475, 70477, 70480, 70480, 70487, 70487, 70493, 70499, 70502, 70508, 70512, 70516, 70656, 70730, 70736, 70745, 70750, 70751, 70784, 70853, 70855, 70855, 70864, 70873, 71040, 71093, 71096, 71104, 71128, 71133, 71168, 71232, 71236, 71236, 71248, 71257, 71296, 71352, 71360, 71369, 71424, 71450, 71453, 71467, 71472, 71481, 71680, 71738, 71840, 71913, 71935, 71935, 72096, 72103, 72106, 72151, 72154, 72161, 72163, 72164, 72192, 72254, 72263, 72263, 72272, 72345, 72349, 72349, 72384, 72440, 72704, 72712, 72714, 72758, 72760, 72768, 72784, 72793, 72818, 72847, 72850, 72871, 72873, 72886, 72960, 72966, 72968, 72969, 72971, 73014, 73018, 73018, 73020, 73021, 73023, 73031, 73040, 73049, 73056, 73061, 73063, 73064, 73066, 73102, 73104, 73105, 73107, 73112, 73120, 73129, 73440, 73462, 73728, 74649, 74752, 74862, 74880, 75075, 77824, 78894, 82944, 83526, 92160, 92728, 92736, 92766, 92768, 92777, 92880, 92909, 92912, 92916, 92928, 92982, 92992, 92995, 93008, 93017, 93027, 93047, 93053, 93071, 93760, 93823, 93952, 94026, 94031, 94087, 94095, 94111, 94176, 94177, 94179, 94179, 94208, 100343, 100352, 101106, 110592, 110878, 110928, 110930, 110948, 110951, 110960, 111355, 113664, 113770, 113776, 113788, 113792, 113800, 113808, 113817, 113821, 113822, 119141, 119145, 119149, 119154, 119163, 119170, 119173, 119179, 119210, 119213, 119362, 119364, 119808, 119892, 119894, 119964, 119966, 119967, 119970, 119970, 119973, 119974, 119977, 119980, 119982, 119993, 119995, 119995, 119997, 120003, 120005, 120069, 120071, 120074, 120077, 120084, 120086, 120092, 120094, 120121, 120123, 120126, 120128, 120132, 120134, 120134, 120138, 120144, 120146, 120485, 120488, 120512, 120514, 120538, 120540, 120570, 120572, 120596, 120598, 120628, 120630, 120654, 120656, 120686, 120688, 120712, 120714, 120744, 120746, 120770, 120772, 120779, 120782, 120831, 121344, 121398, 121403, 121452, 121461, 121461, 121476, 121476, 121499, 121503, 121505, 121519, 122880, 122886, 122888, 122904, 122907, 122913, 122915, 122916, 122918, 122922, 123136, 123180, 123184, 123197, 123200, 123209, 123214, 123214, 123584, 123641, 124928, 125124, 125136, 125142, 125184, 125259, 125264, 125273, 126464, 126467, 126469, 126495, 126497, 126498, 126500, 126500, 126503, 126503, 126505, 126514, 126516, 126519, 126521, 126521, 126523, 126523, 126530, 126530, 126535, 126535, 126537, 126537, 126539, 126539, 126541, 126543, 126545, 126546, 126548, 126548, 126551, 126551, 126553, 126553, 126555, 126555, 126557, 126557, 126559, 126559, 126561, 126562, 126564, 126564, 126567, 126570, 126572, 126578, 126580, 126583, 126585, 126588, 126590, 126590, 126592, 126601, 126603, 126619, 126625, 126627, 126629, 126633, 126635, 126651, 131072, 173782, 173824, 177972, 177984, 178205, 178208, 183969, 183984, 191456, 194560, 195101, 917760, 917999];
    const 关键字头 = new Set([
        102  , 116  , 19981, 20551, 20840, 20849, 20989, 21021, 21024,
        21035, 21407, 21464, 21478, 21482, 21516, 21542, 21551, 22522, 22797, 22823, 22914,
        23383, 23545, 23548, 23567, 23581, 23616, 23646, 24120, 24310,
        24341, 24490, 24658, 25191, 25243, 25351, 25429, 25509, 25972,
        25991, 26029, 26032, 26041, 26080, 26368, 26410, 26412, 26469,
        26500, 26522, 27491, 27979, 29256, 30495, 31243, 31354, 31867,
        32467, 32487, 33509, 34394, 35843, 36143, 36339, 36820, 36873,
        36890, 37322, 40664
    ]);

    export const dlang_VersionIdentifier = new Set(["DigitalMars", "GNU", "LDC", "SDC", "Windows", "Win32", "Win64"
        , "linux", "OSX", "iOS", "TVOS", "WatchOS", "FreeBSD", "OpenBSD", "NetBSD", "DragonFlyBSD", "BSD"
        , "Solaris", "Posix", "AIX", "Haiku", "SkyOS", "SysV3", "SysV4", "Hurd", "Android", "Emscripten"
        , "PlayStation", "PlayStation4", "Cygwin", "MinGW", "FreeStanding", "CRuntime_Bionic", "CRuntime_DigitalMars"
        , "CRuntime_Glibc", "CRuntime_Microsoft", "CRuntime_Musl", "CRuntime_UClibc", "CRuntime_WASI"
        , "CppRuntime_Clang", "CppRuntime_DigitalMars", "CppRuntime_Gcc", "CppRuntime_MicrosoftM"
        , "CppRuntime_Sun", "X86", "X86_64", "ARM", "ARM_Thumb", "ARM_SoftFloat", "ARM_SoftFP"
        , "ARM_HardFloat", "AArch64", "AsmJS", "AVR", "Epiphany", "PPC", "PPC_SoftFloat", "PPC_HardFloat"
        , "PPC64", "IA64", "MIPS32", "MIPS64", "MIPS_O32", "MIPS_N32", "MIPS_O64", "MIPS_N64", "MIPS_EABI"
        , "MIPS_SoftFloat", "MIPS_HardFloat", "MSP430", "NVPTX", "NVPTX64", "RISCV32", "RISCV64", "SPARC"
        , "SPARC_V8Plus", "SPARC_SoftFloat", "SPARC_HardFloat", "SPARC64", "S390", "SystemZ", "HPPA", "HPPA64"
        , "SH", "WebAssembly", "WASI", "Alpha", "Alpha_SoftFloat", "Alpha_HardFloat", "LittleEndian", "BigEndian"
        , "ELFv1", "ELFv2", "D_BetterC", "D_Exceptions", "D_ModuleInfo", "D_TypeInfo", "D_Coverage", "D_Ddoc"
        , "D_InlineAsm_X86", "D_InlineAsm_X86_64", "D_LP64", "D_X32", "D_HardFloat", "D_SoftFloat", "D_PIC", "D_SIMD"
        , "D_AVX", "D_AVX2", "D_Version2", "D_NoBoundsChecks", "D_ObjectiveC"
        , "Core", "Std", "unittest", "assert", "none", "all"])

    
    export const dlang_vs = arrayFrom(dlang_VersionIdentifier.values());

    export const dlang_关键字 = new Set([
        "abstract", "alias", "align", "asm", "assert", "auto", "body",
        "bool", "break", "byte", "case", "cast", "catch", "cdouble", "cent",
        "cfloat", "char", "class", "const", "continue", "creal", "dchar", "debug",
        "default", "delegate", "delete", "deprecated", "do",
        "double", "else", "enum", "export", "extern", "false", "final", "finally",
        "float", "for", "foreach", "foreach_reverse", "function", "goto", "idouble",
        "if", "ifloat", "immutable", "import", "in", "inout", "int", "interface",
        "invariant", "ireal", "is", "lazy", "long", "macro", "mixin", "size_t", "ptrdiff_t",
        "module", "new", "nothrow", "null", "out", "override", "package", "pragma",
        "private", "protected", "public", "pure", "real", "ref", "return", "scope",
        "shared", "short", "static", "struct", "super", "switch", "synchronized",
        "template", "this", "throw", "true", "try", "typeid", "typeof", "ubyte",
        "ucent", "uint", "ulong", "union", "unittest", "ushort", "version",
        "void", "wchar", "while", "with",
        "__FILE__", "__FILE_FULL_PATH__", "__MODULE__", "__LINE__",
        "__FUNCTION__", "__PRETTY_FUNCTION__", "__gshared",
        "__traits", "__vector", "__parameters"
    ]);

    function lookupInUnicodeMap(code: number, map: readonly number[]): boolean {
        // Bail out quickly if it couldn't possibly be in the map.
        if (code < map[0]) {
            return false;
        }

        // Perform binary search in one of the Unicode range maps
        let lo = 0;
        let hi: number = map.length;
        let mid: number;

        while (lo + 1 < hi) {
            mid = lo + (hi - lo) / 2;
            // mid has to be even to catch a range's beginning
            mid -= mid % 2;
            if (map[mid] <= code && code <= map[mid + 1]) {
                return true;
            }

            if (code < map[mid]) {
                hi = mid;
            }
            else {
                lo = mid + 2;
            }
        }

        return false;
    }

    /* @internal */ export function isUnicodeIdentifierStart(code: number) {
        return lookupInUnicodeMap(code, unicodeESNextIdentifierStart)
    }

    function isUnicodeIdentifierPart(code: number) {
        return lookupInUnicodeMap(code, unicodeESNextIdentifierPart)
    }

    function makeReverseMap(source: Map<number>): string[] {
        const result: string[] = [];
        source.forEach((value, name) => {
            result[value] = name;
        });
        return result;
    }

    const tokenStrings = makeReverseMap(textToToken);
    export function tokenToString(t: SyntaxKind): string | undefined {
        return tokenStrings[t];
    }

    const D_tokenStrings: string[] = [];
    D_tokenStrings[SyntaxKind.OpenBraceToken] = "{"
    D_tokenStrings[SyntaxKind.CloseBraceToken] = "}"
    D_tokenStrings[SyntaxKind.OpenParenToken] = "("
    D_tokenStrings[SyntaxKind.CloseParenToken] = ")"
    D_tokenStrings[SyntaxKind.OpenBracketToken] = "["
    D_tokenStrings[SyntaxKind.CloseBracketToken] = "]"
    D_tokenStrings[SyntaxKind.中点号_] = "·"
    D_tokenStrings[SyntaxKind.DotToken] = "."
    D_tokenStrings[SyntaxKind.DotDotDotToken] = "..."    
    D_tokenStrings[SyntaxKind.DotDotToken] = ".."
    D_tokenStrings[SyntaxKind.SemicolonToken] = ";"
    D_tokenStrings[SyntaxKind.CommaToken] = ","
    D_tokenStrings[SyntaxKind.LessThanToken] = "<"
    D_tokenStrings[SyntaxKind.GreaterThanToken] = ">"
    D_tokenStrings[SyntaxKind.LessThanEqualsToken] = "<="
    D_tokenStrings[SyntaxKind.GreaterThanEqualsToken] = ">="
    D_tokenStrings[SyntaxKind.EqualsEqualsToken] = "=="
    D_tokenStrings[SyntaxKind.ExclamationEqualsToken] = "!="
    D_tokenStrings[SyntaxKind.EqualsGreaterThanToken] = "=>"
    D_tokenStrings[SyntaxKind.PlusToken] = "+"
    D_tokenStrings[SyntaxKind.MinusToken] = "-"
    D_tokenStrings[SyntaxKind.AsteriskToken] = "*"
    D_tokenStrings[SyntaxKind.SlashToken] = "/"
    D_tokenStrings[SyntaxKind.PercentToken] = "%"
    D_tokenStrings[SyntaxKind.PlusPlusToken] = "++"
    D_tokenStrings[SyntaxKind.MinusMinusToken] = "--"
    D_tokenStrings[SyntaxKind.LessThanLessThanToken] = "<<"
    D_tokenStrings[SyntaxKind.GreaterThanGreaterThanToken] = ">>"
    D_tokenStrings[SyntaxKind.AmpersandToken] = "&"
    D_tokenStrings[SyntaxKind.BarToken] = "|"
    D_tokenStrings[SyntaxKind.CaretToken] = "^"
    D_tokenStrings[SyntaxKind.ExclamationToken] = "!"
    D_tokenStrings[SyntaxKind.TildeToken] = "~"
    D_tokenStrings[SyntaxKind.AmpersandAmpersandToken] = "&&"
    D_tokenStrings[SyntaxKind.BarBarToken] = "||"
    D_tokenStrings[SyntaxKind.QuestionToken] = "?"
    D_tokenStrings[SyntaxKind.QuestionDotToken] = "?."
    D_tokenStrings[SyntaxKind.ColonToken] = ":"
    D_tokenStrings[SyntaxKind.EqualsToken] = "="
    D_tokenStrings[SyntaxKind.TildeEqualsToken] = "~="
    D_tokenStrings[SyntaxKind.PlusEqualsToken] = "+="
    D_tokenStrings[SyntaxKind.MinusEqualsToken] = "-="
    D_tokenStrings[SyntaxKind.AsteriskEqualsToken] = "*="
    D_tokenStrings[SyntaxKind.SlashEqualsToken] = "/="
    D_tokenStrings[SyntaxKind.PercentEqualsToken] = "%="
    D_tokenStrings[SyntaxKind.LessThanLessThanEqualsToken] = "<<="
    D_tokenStrings[SyntaxKind.GreaterThanGreaterThanEqualsToken] = ">>="
    D_tokenStrings[SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken] = ">>>="
    D_tokenStrings[SyntaxKind.AmpersandEqualsToken] = "&="
    D_tokenStrings[SyntaxKind.BarEqualsToken] = "|="
    D_tokenStrings[SyntaxKind.CaretEqualsToken] = "^="
    D_tokenStrings[SyntaxKind.AtToken] = "@"
    D_tokenStrings[SyntaxKind.BacktickToken] = "`"
    D_tokenStrings[SyntaxKind.MinusGreaterThanToken] = "->"
    D_tokenStrings[SyntaxKind.LessThanMinusToken] = "<-"
    D_tokenStrings[SyntaxKind.ColonGreaterThanToken] = ":>"
    D_tokenStrings[SyntaxKind.ColonEqualsToken] = ":="
    D_tokenStrings[SyntaxKind.点左尖号_] = ".<"
    D_tokenStrings[SyntaxKind.点左括号_] = ".("
    D_tokenStrings[SyntaxKind.DotOpenBracketToken] = ".["
    D_tokenStrings[SyntaxKind.AnyKeyword] = "any"
    D_tokenStrings[SyntaxKind.BooleanKeyword] = "bool"
    D_tokenStrings[SyntaxKind.BreakKeyword] = "break"
    D_tokenStrings[SyntaxKind.CaseKeyword] = "case"
    D_tokenStrings[SyntaxKind.ContinueKeyword] = "continue"
    D_tokenStrings[SyntaxKind.ConstKeyword] = "const"
    D_tokenStrings[SyntaxKind.DebuggerKeyword] = "debug"
    D_tokenStrings[SyntaxKind.DefaultKeyword] = "default"
    D_tokenStrings[SyntaxKind.未定关键字_] = "nil"
    D_tokenStrings[SyntaxKind.DeleteKeyword] = "delete"
    D_tokenStrings[SyntaxKind.ElseKeyword] = "else"
    D_tokenStrings[SyntaxKind.EnumKeyword] = "enum"
    D_tokenStrings[SyntaxKind.FalseKeyword] = "false"
    D_tokenStrings[SyntaxKind.ForKeyword] = "for"
    D_tokenStrings[SyntaxKind.FromKeyword] = "from"
    D_tokenStrings[SyntaxKind.FunctionKeyword] = "function"
    D_tokenStrings[SyntaxKind.IfKeyword] = "if"
    D_tokenStrings[SyntaxKind.ImportKeyword] = "import"
    D_tokenStrings[SyntaxKind.InterfaceKeyword] = "interface"
    D_tokenStrings[SyntaxKind.LetKeyword] = "auto"
    D_tokenStrings[SyntaxKind.NewKeyword] = "new"
    D_tokenStrings[SyntaxKind.NullKeyword] = "null"
    D_tokenStrings[SyntaxKind.ReturnKeyword] = "return"
    D_tokenStrings[SyntaxKind.StringKeyword] = "dstring"
    D_tokenStrings[SyntaxKind.文本8_] = "string"
    D_tokenStrings[SyntaxKind.文本16_] = "wstring"
    D_tokenStrings[SyntaxKind.文本32_] = "dstring"
    D_tokenStrings[SyntaxKind.SwitchKeyword] = "switch"
    D_tokenStrings[SyntaxKind.ThisKeyword] = "this"
    D_tokenStrings[SyntaxKind.基类关键字_] = "super"
    D_tokenStrings[SyntaxKind.TrueKeyword] = "true"
    D_tokenStrings[SyntaxKind.TypeKeyword] = "type"
    D_tokenStrings[SyntaxKind.正量关键字_] = "size_t"
    D_tokenStrings[SyntaxKind.指针关键字_] = "ptrdiff_t"
    D_tokenStrings[SyntaxKind.VoidKeyword] = "void"
    D_tokenStrings[SyntaxKind.不及关键字_] = "assert(0)"
    D_tokenStrings[SyntaxKind.OfKeyword] = "of"
    D_tokenStrings[SyntaxKind.对象关键字_] = "struct"
    D_tokenStrings[SyntaxKind.结构关键字_] = "class"
    D_tokenStrings[SyntaxKind.别名关键字_] = "alias"
    D_tokenStrings[SyntaxKind.另如关键字_] = "else if"
    D_tokenStrings[SyntaxKind.延迟关键字_] = "scope"
    D_tokenStrings[SyntaxKind.程序关键字_] = "module"
    D_tokenStrings[SyntaxKind.启动关键字_] = "main"
    D_tokenStrings[SyntaxKind.初始关键字_] = "this"
    D_tokenStrings[SyntaxKind.释放关键字_] = "~this"
    D_tokenStrings[SyntaxKind.只读关键字_] = "const"
    D_tokenStrings[SyntaxKind.恒定关键字_] = "immutable"
    D_tokenStrings[SyntaxKind.共享关键字_] = "shared"
    D_tokenStrings[SyntaxKind.CatchKeyword] = "catch"
    D_tokenStrings[SyntaxKind.FinallyKeyword] = "finally"
    D_tokenStrings[SyntaxKind.TryKeyword] = "try"
    D_tokenStrings[SyntaxKind.ThrowKeyword] = "throw"
    D_tokenStrings[SyntaxKind.指令关键字_] = "pragma"
    D_tokenStrings[SyntaxKind.汇编关键字_] = "asm"
    D_tokenStrings[SyntaxKind.同步关键字_] = "synchronized"
    D_tokenStrings[SyntaxKind.版本关键字_] = "version"
    D_tokenStrings[SyntaxKind.测试关键字_] = "unittest"
    D_tokenStrings[SyntaxKind.断言关键字_] = "assert"
    D_tokenStrings[SyntaxKind.整数关键字_] = "int"
    D_tokenStrings[SyntaxKind.正整数关键字_] = "uint"
    D_tokenStrings[SyntaxKind.整数8_] = "byte"
    D_tokenStrings[SyntaxKind.整数16_] = "short"
    D_tokenStrings[SyntaxKind.整数32_] = "int"
    D_tokenStrings[SyntaxKind.整数64_] = "long"
    D_tokenStrings[SyntaxKind.正整数8_] = "ubyte"
    D_tokenStrings[SyntaxKind.正整数16_] = "ushort"
    D_tokenStrings[SyntaxKind.正整数32_] = "uint"
    D_tokenStrings[SyntaxKind.正整数64_] = "ulong"
    D_tokenStrings[SyntaxKind.小数关键字_] = "float"
    D_tokenStrings[SyntaxKind.小数32_] = "float"
    D_tokenStrings[SyntaxKind.小数64_] = "double"
    D_tokenStrings[SyntaxKind.虚数32_] = "ifloat"
    D_tokenStrings[SyntaxKind.虚数64_] = "idouble"
    D_tokenStrings[SyntaxKind.复数64_] = "cfloat"
    D_tokenStrings[SyntaxKind.复数128_] = "cdouble"
    D_tokenStrings[SyntaxKind.字符_] = "dchar"
    D_tokenStrings[SyntaxKind.字符8_] = "char"
    D_tokenStrings[SyntaxKind.字符16_] = "wchar"
    D_tokenStrings[SyntaxKind.字符32_] = "dchar"
    D_tokenStrings[SyntaxKind.字节_] = "byte"
    D_tokenStrings[SyntaxKind.UnknownKeyword] = "·unknown"
    D_tokenStrings[SyntaxKind.原型关键字_] = "prototype"

    export function D_tokenToString(t: SyntaxKind): string | undefined {
        return D_tokenStrings[t];
    }

    /* @internal */
    export function stringToToken(s: string): SyntaxKind | undefined {
        return textToToken.get(s);
    }

    /* @internal */
    export function computeLineStarts(text: string): number[] {
        const result: number[] = new Array();
        let pos = 0;
        let lineStart = 0;
        while (pos < text.length) {
            const ch = text.charCodeAt(pos);
            pos++;
            switch (ch) {
                case Charas.carriageReturn:
                    if (text.charCodeAt(pos) === Charas.lineFeed) {
                        pos++;
                    }
                // falls through
                case Charas.lineFeed:
                    result.push(lineStart);
                    lineStart = pos;
                    break;
                default:
                    if (ch > Charas.maxAsciiCharacter && isLineBreak(ch)) {
                        result.push(lineStart);
                        lineStart = pos;
                    }
                    break;
            }
        }
        result.push(lineStart);
        return result;
    }

    export function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number;
    /* @internal */
    export function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number, allowEdits?: true): number; // eslint-disable-line @typescript-eslint/unified-signatures
    export function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number, allowEdits?: true): number {
        return sourceFile.getPositionOfLineAndCharacter ?
            sourceFile.getPositionOfLineAndCharacter(line, character, allowEdits) :
            computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character, sourceFile.text, allowEdits);
    }

    /* @internal */
    export function computePositionOfLineAndCharacter(lineStarts: readonly number[], line: number, character: number, debugText?: string, allowEdits?: true): number {
        if (line < 0 || line >= lineStarts.length) {
            if (allowEdits) {
                // Clamp line to nearest allowable value
                line = line < 0 ? 0 : line >= lineStarts.length ? lineStarts.length - 1 : line;
            }
            else {
                Debug.fail(`Bad line number. Line: ${line}, lineStarts.length: ${lineStarts.length} , line map is correct? ${debugText !== undefined ? arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown"}`);
            }
        }

        const res = lineStarts[line] + character;
        if (allowEdits) {
            // Clamp to nearest allowable values to allow the underlying to be edited without crashing (accuracy is lost, instead)
            // TODO: Somehow track edits between file as it was during the creation of sourcemap we have and the current file and
            // apply them to the computed position to improve accuracy
            return res > lineStarts[line + 1] ? lineStarts[line + 1] : typeof debugText === "string" && res > debugText.length ? debugText.length : res;
        }
        if (line < lineStarts.length - 1) {
            Debug.assert(res < lineStarts[line + 1]);
        }
        else if (debugText !== undefined) {
            Debug.assert(res <= debugText.length); // Allow single character overflow for trailing newline
        }
        return res;
    }

    /* @internal */
    export function getLineStarts(sourceFile: SourceFileLike): readonly number[] {
        return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
    }

    /* @internal */
    /**
     * We assume the first line starts at position 0 and 'position' is non-negative.
     */
    export function computeLineAndCharacterOfPosition(lineStarts: readonly number[], position: number): LineAndCharacter {
        let lineNumber = binarySearch(lineStarts, position, identity, compareValues);
        if (lineNumber < 0) {
            // If the actual position was not found,
            // the binary search returns the 2's-complement of the next line start
            // e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20
            // then the search will return -2.
            //
            // We want the index of the previous line start, so we subtract 1.
            // Review 2's-complement if this is confusing.
            lineNumber = ~lineNumber - 1;
            Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file");
        }
        return {
            line: lineNumber,
            character: position - lineStarts[lineNumber]
        };
    }

    export function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter {
        return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
    }

    export function isWhiteSpaceLike(ch: number): boolean {
        return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
    }

    /** Does not include line breaks. For that, see isWhiteSpaceLike. */
    export function isWhiteSpaceSingleLine(ch: number): boolean {
        // Note: nextLine is in the Zs space, and should be considered to be a whitespace.
        // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
        return ch === Charas.space ||
            ch === Charas.tab ||
            ch === Charas.verticalTab ||
            ch === Charas.formFeed ||
            ch === Charas.nonBreakingSpace ||
            ch === Charas.nextLine ||
            ch === Charas.ogham ||
            ch >= Charas.enQuad && ch <= Charas.zeroWidthSpace ||
            ch === Charas.narrowNoBreakSpace ||
            ch === Charas.mathematicalSpace ||
            ch === Charas.ideographicSpace ||
            ch === Charas.byteOrderMark;
    }

    export function isLineBreak(ch: number): boolean {
        // ES5 7.3:
        // The ECMAScript line terminator characters are listed in Table 3.
        //     Table 3: Line Terminator Characters
        //     Code Unit Value     Name                    Formal Name
        //     \u000A              Line Feed               <LF>
        //     \u000D              Carriage Return         <CR>
        //     \u2028              Line separator          <LS>
        //     \u2029              Paragraph separator     <PS>
        // Only the characters in Table 3 are treated as line terminators. Other new line or line
        // breaking characters are treated as white space but not as line terminators.

        return ch === Charas.lineFeed ||
            ch === Charas.carriageReturn ||
            ch === Charas.lineSeparator ||
            ch === Charas.paragraphSeparator;
    }

    function isDigit(ch: number): boolean {
        return ch >= Charas._0 && ch <= Charas._9;
    }

    /* @internal */
    export function isOctalDigit(ch: number): boolean {
        return ch >= Charas._0 && ch <= Charas._7;
    }

    export function couldStartTrivia(text: string, pos: number): boolean {
        // Keep in sync with skipTrivia
        const ch = text.charCodeAt(pos);
        switch (ch) {
            case Charas.carriageReturn:
            case Charas.lineFeed:
            case Charas.tab:
            case Charas.verticalTab:
            case Charas.formFeed:
            case Charas.space:
            case Charas.slash:
            // starts of normal trivia
            // falls through
            case Charas.lessThan:
            case Charas.bar:
            case Charas.equals:
            case Charas.greaterThan:
                // Starts of conflict marker trivia
                return true;
            case Charas.hash:
                // Only if its the beginning can we have #! trivia
                return pos === 0;
            default:
                return ch > Charas.maxAsciiCharacter;
        }
    }

    /* @internal */
    export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean, stopAtComments = false): number {
        if (positionIsSynthesized(pos)) {
            return pos;
        }

        // Keep in sync with couldStartTrivia
        while (true) {
            const ch = text.charCodeAt(pos);
            switch (ch) {
                case Charas.carriageReturn:
                    if (text.charCodeAt(pos + 1) === Charas.lineFeed) {
                        pos++;
                    }
                // falls through
                case Charas.lineFeed:
                    pos++;
                    if (stopAfterLineBreak) {
                        return pos;
                    }
                    continue;
                case Charas.tab:
                case Charas.verticalTab:
                case Charas.formFeed:
                case Charas.space:
                    pos++;
                    continue;
                case Charas.slash:
                    if (stopAtComments) {
                        break;
                    }
                    if (text.charCodeAt(pos + 1) === Charas.slash) {
                        pos += 2;
                        while (pos < text.length) {
                            if (isLineBreak(text.charCodeAt(pos))) {
                                break;
                            }
                            pos++;
                        }
                        continue;
                    }
                    if (text.charCodeAt(pos + 1) === Charas.asterisk) {
                        pos += 2;
                        while (pos < text.length) {
                            if (text.charCodeAt(pos) === Charas.asterisk && text.charCodeAt(pos + 1) === Charas.slash) {
                                pos += 2;
                                break;
                            }
                            pos++;
                        }
                        continue;
                    }
                    break;

                case Charas.lessThan:
                case Charas.bar:
                case Charas.equals:
                case Charas.greaterThan:
                    if (isConflictMarkerTrivia(text, pos)) {
                        pos = scanConflictMarkerTrivia(text, pos);
                        continue;
                    }
                    break;

                case Charas.hash:

                    if (pos === 0 && isShebangTrivia(text, pos)) {
                        pos = scanShebangTrivia(text, pos);
                        continue;
                    }
                    break;

                default:
                    if (ch > Charas.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
                        pos++;
                        continue;
                    }
                    break;
            }
            return pos;
        }
    }

    // All conflict markers consist of the same character repeated seven times.  If it is
    // a <<<<<<< or >>>>>>> marker then it is also followed by a space.
    const mergeConflictMarkerLength = "<<<<<<<".length;

    function isConflictMarkerTrivia(text: string, pos: number) {
        Debug.assert(pos >= 0);

        // Conflict markers must be at the start of a line.
        if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
            const ch = text.charCodeAt(pos);

            if ((pos + mergeConflictMarkerLength) < text.length) {
                for (let i = 0; i < mergeConflictMarkerLength; i++) {
                    if (text.charCodeAt(pos + i) !== ch) {
                        return false;
                    }
                }

                return ch === Charas.equals ||
                    text.charCodeAt(pos + mergeConflictMarkerLength) === Charas.space;
            }
        }

        return false;
    }

    function scanConflictMarkerTrivia(text: string, pos: number, error?: (diag: DiagnosticMessage, pos?: number, len?: number) => void) {
        if (error) {
            error(Diagnostics.Merge_conflict_marker_encountered, pos, mergeConflictMarkerLength);
        }

        const ch = text.charCodeAt(pos);
        const len = text.length;

        if (ch === Charas.lessThan || ch === Charas.greaterThan) {
            while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
                pos++;
            }
        }
        else {
            Debug.assert(ch === Charas.bar || ch === Charas.equals);
            // Consume everything from the start of a ||||||| or ======= marker to the start
            // of the next ======= or >>>>>>> marker.
            while (pos < len) {
                const currentChar = text.charCodeAt(pos);
                if ((currentChar === Charas.equals || currentChar === Charas.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
                    break;
                }

                pos++;
            }
        }

        return pos;
    }

    const shebangTriviaRegex = /^#!.*/;

    /*@internal*/
    export function isShebangTrivia(text: string, pos: number) {
        // Shebangs check must only be done at the start of the file
        Debug.assert(pos === 0);
        return shebangTriviaRegex.test(text);
    }

    /*@internal*/
    export function scanShebangTrivia(text: string, pos: number) {
        const shebang = shebangTriviaRegex.exec(text)![0];
        pos = pos + shebang.length;
        return pos;
    }

    /**
     * Invokes a callback for each comment range following the provided position.
     *
     * Single-line comment ranges include the leading double-slash characters but not the ending
     * line break. Multi-line comment ranges include the leading slash-asterisk and trailing
     * asterisk-slash characters.
     *
     * @param reduce If true, accumulates the result of calling the callback in a fashion similar
     *      to reduceLeft. If false, iteration stops when the callback returns a truthy value.
     * @param text The source text to scan.
     * @param pos The position at which to start scanning.
     * @param trailing If false, whitespace is skipped until the first line break and comments
     *      between that location and the next token are returned. If true, comments occurring
     *      between the given position and the next line break are returned.
     * @param cb The callback to execute as each comment range is encountered.
     * @param state A state value to pass to each iteration of the callback.
     * @param initial An initial value to pass when accumulating results (when "reduce" is true).
     * @returns If "reduce" is true, the accumulated value. If "reduce" is false, the first truthy
     *      return value of the callback.
     */
    function iterateCommentRanges<T, U>(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U | undefined) => U, state: T, initial?: U): U | undefined {
        let pendingPos!: number;
        let pendingEnd!: number;
        let pendingKind!: CommentKind;
        let pendingHasTrailingNewLine!: boolean;
        let hasPendingCommentRange = false;
        let collecting = trailing;
        let accumulator = initial;
        if (pos === 0) {
            collecting = true;
            const shebang = getShebang(text);
            if (shebang) {
                pos = shebang.length;
            }
        }
        scan: while (pos >= 0 && pos < text.length) {
            const ch = text.charCodeAt(pos);
            switch (ch) {
                case Charas.carriageReturn:
                    if (text.charCodeAt(pos + 1) === Charas.lineFeed) {
                        pos++;
                    }
                // falls through
                case Charas.lineFeed:
                    pos++;
                    if (trailing) {
                        break scan;
                    }

                    collecting = true;
                    if (hasPendingCommentRange) {
                        pendingHasTrailingNewLine = true;
                    }

                    continue;
                case Charas.tab:
                case Charas.verticalTab:
                case Charas.formFeed:
                case Charas.space:
                    pos++;
                    continue;
                case Charas.slash:
                    const nextChar = text.charCodeAt(pos + 1);
                    let hasTrailingNewLine = false;
                    if (nextChar === Charas.slash || nextChar === Charas.asterisk) {
                        const kind = nextChar === Charas.slash ? SyntaxKind.SingleLineCommentTrivia : SyntaxKind.MultiLineCommentTrivia;
                        const startPos = pos;
                        pos += 2;
                        if (nextChar === Charas.slash) {
                            while (pos < text.length) {
                                if (isLineBreak(text.charCodeAt(pos))) {
                                    hasTrailingNewLine = true;
                                    break;
                                }
                                pos++;
                            }
                        }
                        else {
                            while (pos < text.length) {
                                if (text.charCodeAt(pos) === Charas.asterisk && text.charCodeAt(pos + 1) === Charas.slash) {
                                    pos += 2;
                                    break;
                                }
                                pos++;
                            }
                        }

                        if (collecting) {
                            if (hasPendingCommentRange) {
                                accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator);
                                if (!reduce && accumulator) {
                                    // If we are not reducing and we have a truthy result, return it.
                                    return accumulator;
                                }
                            }

                            pendingPos = startPos;
                            pendingEnd = pos;
                            pendingKind = kind;
                            pendingHasTrailingNewLine = hasTrailingNewLine;
                            hasPendingCommentRange = true;
                        }

                        continue;
                    }
                    break scan;
                default:
                    if (ch > Charas.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
                        if (hasPendingCommentRange && isLineBreak(ch)) {
                            pendingHasTrailingNewLine = true;
                        }
                        pos++;
                        continue;
                    }
                    break scan;
            }
        }

        if (hasPendingCommentRange) {
            accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator);
        }

        return accumulator;
    }

    export function forEachLeadingCommentRange<U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined;
    export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined;
    export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state?: T): U | undefined {
        return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ false, cb, state);
    }

    export function forEachTrailingCommentRange<U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined;
    export function forEachTrailingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined;
    export function forEachTrailingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state?: T): U | undefined {
        return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ true, cb, state);
    }

    export function reduceEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) {
        return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial);
    }

    export function reduceEachTrailingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) {
        return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ true, cb, state, initial);
    }

    function appendCommentRange(pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, _state: any, comments: CommentRange[]) {
        if (!comments) {
            comments = [];
        }

        comments.push({ kind, pos, end, hasTrailingNewLine });
        return comments;
    }

    export function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined {
        return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
    }

    export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined {
        return reduceEachTrailingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
    }

    /** Optionally, get the shebang */
    export function getShebang(text: string): string | undefined {
        const match = shebangTriviaRegex.exec(text);
        if (match) {
            return match[0];
        }
    }

    export function isIdentifierStart(ch: number): boolean {
        return ch >= Charas.A && ch <= Charas.Z || ch >= Charas.a && ch <= Charas.z ||
            ch === Charas.$ || ch === Charas._ ||
            ch > Charas.maxAsciiCharacter && isUnicodeIdentifierStart(ch);
    }

    export function isIdentifierPart(ch: number): boolean {
        return ch >= Charas.A && ch <= Charas.Z || ch >= Charas.a && ch <= Charas.z ||
            ch >= Charas._0 && ch <= Charas._9 || ch === Charas.$ || ch === Charas._ ||
            ch > Charas.maxAsciiCharacter && isUnicodeIdentifierPart(ch);
    }

    /* @internal */
    export function isIdentifierText(name: string): boolean {
        let ch = codePointAt(name, 0);
        if (!isIdentifierStart(ch) && ch !== Charas.中点_) {
            return false;
        }

        for (let i = charSize(ch); i < name.length; i += charSize(ch)) {
            if (!isIdentifierPart(ch = codePointAt(name, i))) {
                return false;
            }
        }

        return true;
    }

    // Creates a scanner over a (possibly unspecified) range of a piece of text.
    export function createScanner(
        skipTrivia: boolean,
        textInitial?: string,
        onError?: ErrorCallback,
        start?: number,
        length?: number): Scanner {

        let text = textInitial!;

        // Current position (end position of text of current token)
        let pos: number;


        // end of text
        let end: number;

        // Start position of whitespace before current token
        let startPos: number;

        // Start position of text of current token
        let tokenPos: number;

        let token: SyntaxKind;
        let tokenValue!: string;
        let tokenFlags: TokenFlags;

        let inJSDocType = 0;

        setText(text, start, length);

        const scanner: Scanner = {
            getStartPos: () => startPos,
            getTextPos: () => pos,
            getToken: () => token,
            getTokenPos: () => tokenPos,
            getTokenText: () => text.substring(tokenPos, pos),
            getTokenValue: () => tokenValue,
            hasUnicodeEscape: () => (tokenFlags & TokenFlags.UnicodeEscape) !== 0,
            hasExtendedUnicodeEscape: () => (tokenFlags & TokenFlags.ExtendedUnicodeEscape) !== 0,
            hasPrecedingLineBreak: () => (tokenFlags & TokenFlags.PrecedingLineBreak) !== 0,
            isIdentifier: () => token === SyntaxKind.Identifier || token > SyntaxKind.LastReservedWord,
            isReservedWord: () => token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord,
            isUnterminated: () => (tokenFlags & TokenFlags.Unterminated) !== 0,
            getTokenFlags: () => tokenFlags,
            reScanGreaterToken,
            reScanSlashToken,
            reScanTemplateToken,
            reScanLessThanToken,
            scanJsDocToken,
            扫描词典语句令牌,
            scan,
            getText,
            setText,
            setOnError,
            setTextPos,
            setInJSDocType,
            tryScan,
            lookAhead,
            scanRange,
        };

        if (Debug.isDebugging) {
            Object.defineProperty(scanner, "__debugShowCurrentPositionInText", {
                get: () => {
                    const text = scanner.getText();
                    return text.slice(0, scanner.getStartPos()) + "║" + text.slice(scanner.getStartPos());
                },
            });
        }

        return scanner;

        function error(message: DiagnosticMessage): void;
        function error(message: DiagnosticMessage, errPos: number, length: number): void;
        function error(message: DiagnosticMessage, errPos: number = pos, length?: number): void {
            if (onError) {
                const oldPos = pos;
                pos = errPos;
                onError(message, length || 0);
                pos = oldPos;
            }
        }

        function scanNumberFragment(): string {
            let start = pos;
            let allowSeparator = false;
            let isPreviousTokenSeparator = false;
            let result = "";
            while (true) {
                const ch = text.charCodeAt(pos);
                if (ch === Charas._) {
                    tokenFlags |= TokenFlags.ContainsSeparator;
                    if (allowSeparator) {
                        allowSeparator = false;
                        isPreviousTokenSeparator = true;
                        result += text.substring(start, pos);
                    }
                    else if (isPreviousTokenSeparator) {
                        error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
                    }
                    else {
                        error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
                    }
                    pos++;
                    start = pos;
                    continue;
                }
                if (isDigit(ch)) {
                    allowSeparator = true;
                    isPreviousTokenSeparator = false;
                    pos++;
                    continue;
                }
                break;
            }
            if (text.charCodeAt(pos - 1) === Charas._) {
                error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
            }
            return result + text.substring(start, pos);
        }

        function scanNumber(): { type: SyntaxKind, value: string } {
            const start = pos;
            const mainFragment = scanNumberFragment();
            let decimalFragment: string | undefined;
            let scientificFragment: string | undefined;
            if (text.charCodeAt(pos) === Charas.dot && text.charCodeAt(pos + 1) !== Charas.dot) {
                pos++;
                tokenFlags |= TokenFlags.是小数_
                decimalFragment = scanNumberFragment();
            }
            let end = pos;
            if (text.charCodeAt(pos) === Charas.E || text.charCodeAt(pos) === Charas.e) {
                pos++;
                tokenFlags |= TokenFlags.Scientific;
                if (text.charCodeAt(pos) === Charas.plus || text.charCodeAt(pos) === Charas.minus) pos++;
                const preNumericPart = pos;
                const finalFragment = scanNumberFragment();
                if (!finalFragment) {
                    error(Diagnostics.Digit_expected);
                }
                else {
                    scientificFragment = text.substring(end, preNumericPart) + finalFragment;
                    end = pos;
                }
            }
            let result: string;
            if (tokenFlags & TokenFlags.ContainsSeparator) {
                result = mainFragment;
                if (decimalFragment) {
                    result += "." + decimalFragment;
                }
                if (scientificFragment) {
                    result += scientificFragment;
                }
            }
            else {
                result = text.substring(start, end); // No need to use all the fragments; no _ removal needed
            }

            if (decimalFragment !== undefined || tokenFlags & TokenFlags.Scientific) {
                if ((text.charCodeAt(pos) === Charas.F || text.charCodeAt(pos) === Charas.f) && text.charCodeAt(pos + 1) === Charas.i) {
                    pos += 2;
                    tokenFlags |= TokenFlags.FI_;
                }
                else if (text.charCodeAt(pos) === Charas.F || text.charCodeAt(pos) === Charas.f) {
                    pos++;
                    tokenFlags |= TokenFlags.F_;
                }
                else if (text.charCodeAt(pos) === Charas.i) {
                    pos++;
                    tokenFlags |= TokenFlags.I_;
                }
                checkForIdentifierStartAfterNumericLiteral(start, decimalFragment === undefined && !!(tokenFlags & TokenFlags.Scientific));
                return {
                    type: SyntaxKind.NumericLiteral,
                    value: "" + result // if value is not an integer, it can be safely coerced to a number
                };
            }
            else {
                tokenValue = result;
                const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint
                checkForIdentifierStartAfterNumericLiteral(start);
                return { type, value: tokenValue };
            }
        }

        function checkForIdentifierStartAfterNumericLiteral(numericStart: number, isScientific?: boolean) {
            if (!isIdentifierStart(codePointAt(text, pos))) {
                return;
            }

            const identifierStart = pos;
            const { length } = scanIdentifierParts();

            if (length === 1 && text[identifierStart] === "n") {
                if (isScientific) {
                    error(Diagnostics.A_bigint_literal_cannot_use_exponential_notation, numericStart, identifierStart - numericStart + 1);
                }
                else {
                    error(Diagnostics.A_bigint_literal_must_be_an_integer, numericStart, identifierStart - numericStart + 1);
                }
            }
            else {
                error(Diagnostics.An_identifier_or_keyword_cannot_immediately_follow_a_numeric_literal, identifierStart, length);
                pos = identifierStart;
            }
        }

        function scanOctalDigits(): number {
            const start = pos;
            while (isOctalDigit(text.charCodeAt(pos))) {
                pos++;
            }
            return +(text.substring(start, pos));
        }

        /**
         * Scans the given number of hexadecimal digits in the text,
         * returning -1 if the given number is unavailable.
         */
        function scanExactNumberOfHexDigits(count: number, canHaveSeparators: boolean): number {
            const valueString = scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false, canHaveSeparators);
            return valueString ? parseInt(valueString, 16) : -1;
        }

        /**
         * Scans as many hexadecimal digits as are available in the text,
         * returning "" if the given number of digits was unavailable.
         */
        function scanMinimumNumberOfHexDigits(count: number, canHaveSeparators: boolean): string {
            return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ true, canHaveSeparators);
        }

        function scanHexDigits(minCount: number, scanAsManyAsPossible: boolean, canHaveSeparators: boolean): string {
            let valueChars: number[] = [];
            let allowSeparator = false;
            let isPreviousTokenSeparator = false;
            while (valueChars.length < minCount || scanAsManyAsPossible) {
                let ch = text.charCodeAt(pos);
                if (canHaveSeparators && ch === Charas._) {
                    tokenFlags |= TokenFlags.ContainsSeparator;
                    if (allowSeparator) {
                        allowSeparator = false;
                        isPreviousTokenSeparator = true;
                    }
                    else if (isPreviousTokenSeparator) {
                        error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
                    }
                    else {
                        error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
                    }
                    pos++;
                    continue;
                }
                allowSeparator = canHaveSeparators;
                if (ch >= Charas.A && ch <= Charas.F) {
                    ch += Charas.a - Charas.A; // standardize hex literals to lowercase
                }
                else if (!((ch >= Charas._0 && ch <= Charas._9) ||
                    (ch >= Charas.a && ch <= Charas.f)
                )) {
                    break;
                }
                valueChars.push(ch);
                pos++;
                isPreviousTokenSeparator = false;
            }
            if (valueChars.length < minCount) {
                valueChars = [];
            }
            if (text.charCodeAt(pos - 1) === Charas._) {
                error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
            }
            return String.fromCharCode(...valueChars);
        }

        function scanString(jsxAttributeString = false): string {
            const quote = text.charCodeAt(pos);
            pos++;
            let result = "";
            let start = pos;
            while (true) {
                if (pos >= end) {
                    result += text.substring(start, pos);
                    tokenFlags |= TokenFlags.Unterminated;
                    error(Diagnostics.Unterminated_string_literal);
                    break;
                }
                const ch = text.charCodeAt(pos);
                if (ch === quote) {
                    result += text.substring(start, pos);
                    pos++;
                    break;
                }
                if (ch === Charas.backslash && !jsxAttributeString) {
                    result += text.substring(start, pos);
                    result += scanEscapeSequence();
                    start = pos;
                    continue;
                }
                if (isLineBreak(ch) && !jsxAttributeString) {
                    result += text.substring(start, pos);
                    tokenFlags |= TokenFlags.Unterminated;
                    error(Diagnostics.Unterminated_string_literal);
                    break;
                }
                pos++;
            }
            return result;
        }

        /**
         * Sets the current 'tokenValue' and returns a NoSubstitutionTemplateLiteral or
         * a literal component of a TemplateExpression.
         */
        function scanTemplateAndSetTokenValue(): SyntaxKind {
            const startedWithBacktick = text.charCodeAt(pos) === Charas.backtick;

            pos++;
            let start = pos;
            let contents = "";
            let resultingToken: SyntaxKind;

            while (true) {
                if (pos >= end) {
                    contents += text.substring(start, pos);
                    tokenFlags |= TokenFlags.Unterminated;
                    error(Diagnostics.Unterminated_template_literal);
                    resultingToken = startedWithBacktick ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail;
                    break;
                }

                const currChar = text.charCodeAt(pos);

                // '`'
                if (currChar === Charas.backtick) {
                    contents += text.substring(start, pos);
                    pos++;
                    resultingToken = startedWithBacktick ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail;
                    break;
                }

                // '${'
                if (currChar === Charas.$ && pos + 1 < end && text.charCodeAt(pos + 1) === Charas.openBrace) {
                    contents += text.substring(start, pos);
                    pos += 2;
                    resultingToken = startedWithBacktick ? SyntaxKind.TemplateHead : SyntaxKind.TemplateMiddle;
                    break;
                }

                // Escape character
                if (currChar === Charas.backslash) {
                    contents += text.substring(start, pos);
                    contents += scanEscapeSequence();
                    start = pos;
                    continue;
                }

                // Speculated ECMAScript 6 Spec 11.8.6.1:
                // <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> for Template Values
                if (currChar === Charas.carriageReturn) {
                    contents += text.substring(start, pos);
                    pos++;

                    if (pos < end && text.charCodeAt(pos) === Charas.lineFeed) {
                        pos++;
                    }

                    contents += "\n";
                    start = pos;
                    continue;
                }

                pos++;
            }

            Debug.assert(resultingToken !== undefined);

            tokenValue = contents;
            return resultingToken;
        }

        function scanEscapeSequence(): string {
            pos++;
            if (pos >= end) {
                error(Diagnostics.Unexpected_end_of_text);
                return "";
            }
            const ch = text.charCodeAt(pos);
            pos++;
            switch (ch) {
                case Charas._0:
                    return "\0";
                case Charas.b:
                    return "\b";
                case Charas.t:
                    return "\t";
                case Charas.n:
                    return "\n";
                case Charas.v:
                    return "\v";
                case Charas.f:
                    return "\f";
                case Charas.r:
                    return "\r";
                case Charas.singleQuote:
                    return "\'";
                case Charas.doubleQuote:
                    return "\"";
                case Charas.u:
                    // '\u{DDDDDDDD}'
                    if (pos < end && text.charCodeAt(pos) === Charas.openBrace) {
                        tokenFlags |= TokenFlags.ExtendedUnicodeEscape;
                        pos++;
                        return scanExtendedUnicodeEscape();
                    }

                    tokenFlags |= TokenFlags.UnicodeEscape;
                    // '\uDDDD'
                    return scanHexadecimalEscape(/*numDigits*/ 4);

                case Charas.x:
                    // '\xDD'
                    return scanHexadecimalEscape(/*numDigits*/ 2);

                // when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
                // the line terminator is interpreted to be "the empty code unit sequence".
                case Charas.carriageReturn:
                    if (pos < end && text.charCodeAt(pos) === Charas.lineFeed) {
                        pos++;
                    }
                // falls through
                case Charas.lineFeed:
                case Charas.lineSeparator:
                case Charas.paragraphSeparator:
                    return "";
                default:
                    return String.fromCharCode(ch);
            }
        }

        function scanHexadecimalEscape(numDigits: number): string {
            const escapedValue = scanExactNumberOfHexDigits(numDigits, /*canHaveSeparators*/ false);

            if (escapedValue >= 0) {
                return String.fromCharCode(escapedValue);
            }
            else {
                error(Diagnostics.Hexadecimal_digit_expected);
                return "";
            }
        }

        function scanExtendedUnicodeEscape(): string {
            const escapedValueString = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
            const escapedValue = escapedValueString ? parseInt(escapedValueString, 16) : -1;
            let isInvalidExtendedEscape = false;

            // Validate the value of the digit
            if (escapedValue < 0) {
                error(Diagnostics.Hexadecimal_digit_expected);
                isInvalidExtendedEscape = true;
            }
            else if (escapedValue > 0x10FFFF) {
                error(Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
                isInvalidExtendedEscape = true;
            }

            if (pos >= end) {
                error(Diagnostics.Unexpected_end_of_text);
                isInvalidExtendedEscape = true;
            }
            else if (text.charCodeAt(pos) === Charas.closeBrace) {
                // Only swallow the following character up if it's a '}'.
                pos++;
            }
            else {
                error(Diagnostics.Unterminated_Unicode_escape_sequence);
                isInvalidExtendedEscape = true;
            }

            if (isInvalidExtendedEscape) {
                return "";
            }

            return utf16EncodeAsString(escapedValue);
        }

        // Derived from the 10.1.1 UTF16Encoding of the ES6 Spec.
        function utf16EncodeAsString(codePoint: number): string {
            Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);

            if (codePoint <= 65535) {
                return String.fromCharCode(codePoint);
            }

            const codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
            const codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;

            return String.fromCharCode(codeUnit1, codeUnit2);
        }

        // Current character is known to be a backslash. Check for Unicode escape of the form '\uXXXX'
        // and return code point value if valid Unicode escape is found. Otherwise return -1.
        function peekUnicodeEscape(): number {
            if (pos + 5 < end && text.charCodeAt(pos + 1) === Charas.u) {
                const start = pos;
                pos += 2;
                const value = scanExactNumberOfHexDigits(4, /*canHaveSeparators*/ false);
                pos = start;
                return value;
            }
            return -1;
        }


        function peekExtendedUnicodeEscape(): number {
            if (codePointAt(text, pos + 1) === Charas.u && codePointAt(text, pos + 2) === Charas.openBrace) {
                const start = pos;
                pos += 3;
                const escapedValueString = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
                const escapedValue = escapedValueString ? parseInt(escapedValueString, 16) : -1;
                pos = start;
                return escapedValue;
            }
            return -1;
        }

        function scanIdentifierParts(): string {
            let result = "";
            let start = pos;
            while (pos < end) {
                let ch = codePointAt(text, pos);
                if (isIdentifierPart(ch)) {
                    pos += charSize(ch);
                }
                else if (ch === Charas.backslash) {
                    ch = peekExtendedUnicodeEscape();
                    if (ch >= 0 && isIdentifierPart(ch)) {
                        pos += 3;
                        tokenFlags |= TokenFlags.ExtendedUnicodeEscape;
                        result += scanExtendedUnicodeEscape();
                        start = pos;
                        continue;
                    }
                    ch = peekUnicodeEscape();
                    if (!(ch >= 0 && isIdentifierPart(ch))) {
                        break;
                    }
                    tokenFlags |= TokenFlags.UnicodeEscape;
                    result += text.substring(start, pos);
                    result += utf16EncodeAsString(ch);
                    // Valid Unicode escape is always six characters
                    pos += 6;
                    start = pos;
                }
                else {
                    break;
                }
            }
            result += text.substring(start, pos);
            return result;
        }

        function getIdentifierToken(): SyntaxKind.Identifier | KeywordSyntaxKind | SyntaxKind.Unknown {
            const ch = tokenValue.charCodeAt(0);
            if (关键字头.has(ch)) {
                const keyword = textToKeyword.get(tokenValue);
                if (keyword !== undefined) {
                    return token = keyword;
                }
            }
            if (dlang_关键字.has(tokenValue)) {
                error(Diagnostics.保留关键字不能作为标识符);
                return token = SyntaxKind.Unknown;
            }
            if (ch === Charas._) {
                tokenValue.length === 1 ? tokenFlags |= TokenFlags.是空标识符_ : tokenFlags |= TokenFlags.是私有的_
            }
            return token = SyntaxKind.Identifier;
        }

        function scanBinaryOrOctalDigits(base: 2 | 8): string {
            let value = "";
            // For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b.
            // Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
            let separatorAllowed = false;
            let isPreviousTokenSeparator = false;
            while (true) {
                const ch = text.charCodeAt(pos);
                // Numeric separators are allowed anywhere within a numeric literal, except not at the beginning, or following another separator
                if (ch === Charas._) {
                    tokenFlags |= TokenFlags.ContainsSeparator;
                    if (separatorAllowed) {
                        separatorAllowed = false;
                        isPreviousTokenSeparator = true;
                    }
                    else if (isPreviousTokenSeparator) {
                        error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
                    }
                    else {
                        error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
                    }
                    pos++;
                    continue;
                }
                separatorAllowed = true;
                if (!isDigit(ch) || ch - Charas._0 >= base) {
                    break;
                }
                value += text[pos];
                pos++;
                isPreviousTokenSeparator = false;
            }
            if (text.charCodeAt(pos - 1) === Charas._) {
                // Literal ends with underscore - not allowed
                error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
            }
            return value;
        }

        function checkBigIntSuffix(): SyntaxKind {
            if (text.charCodeAt(pos) === Charas.n) {
                tokenValue += "n";
                // Use base 10 instead of base 2 or base 8 for shorter literals
                if (tokenFlags & TokenFlags.BinaryOrOctalSpecifier) {
                    tokenValue = parsePseudoBigInt(tokenValue) + "n";
                }
                pos++;
                return SyntaxKind.BigIntLiteral;
            }
            else {
                // not a bigint, so can convert to number in simplified form
                // Number() may not support 0b or 0o, so use parseInt() instead                
                计算二进制或八进制();
                if ((text.charCodeAt(pos) === Charas.U || text.charCodeAt(pos) === Charas.u) && text.charCodeAt(pos + 1) === Charas.L) {
                    pos += 2;
                    tokenFlags |= TokenFlags.UL_;
                }
                else if (text.charCodeAt(pos) === Charas.L) {
                    pos++;
                    tokenFlags |= TokenFlags.L_;
                }
                else if (text.charCodeAt(pos) === Charas.U || text.charCodeAt(pos) === Charas.u) {
                    pos++;
                    tokenFlags |= TokenFlags.U_;
                }
                return SyntaxKind.NumericLiteral;
            }
        }

        function 计算二进制或八进制() {
            const numericValue = tokenFlags & TokenFlags.BinarySpecifier
                ? parseInt(tokenValue.slice(2), 2) // skip "0b"
                : tokenFlags & TokenFlags.OctalSpecifier
                    ? parseInt(tokenValue.slice(2), 8) // skip "0o"
                    : +tokenValue;
            tokenValue = "" + numericValue;
        }

        function scan(): SyntaxKind {
            startPos = pos;
            tokenFlags = TokenFlags.None;
            let asteriskSeen = false;
            while (true) {
                tokenPos = pos;
                if (pos >= end) {
                    return token = SyntaxKind.EndOfFileToken;
                }
                let ch = codePointAt(text, pos);

                // Special handling for shebang
                if (ch === Charas.hash && pos === 0 && isShebangTrivia(text, pos)) {
                    pos = scanShebangTrivia(text, pos);
                    if (skipTrivia) {
                        continue;
                    }
                    else {
                        return token = SyntaxKind.ShebangTrivia;
                    }
                }

                switch (ch) {
                    case Charas.lineFeed:
                    case Charas.carriageReturn:
                        tokenFlags |= TokenFlags.PrecedingLineBreak;
                        if (skipTrivia) {
                            pos++;
                            continue;
                        }
                        else {
                            if (ch === Charas.carriageReturn && pos + 1 < end && text.charCodeAt(pos + 1) === Charas.lineFeed) {
                                // consume both CR and LF
                                pos += 2;
                            }
                            else {
                                pos++;
                            }
                            return token = SyntaxKind.NewLineTrivia;
                        }
                    case Charas.tab:
                    case Charas.verticalTab:
                    case Charas.formFeed:
                    case Charas.space:
                    case Charas.nonBreakingSpace:
                    case Charas.ogham:
                    case Charas.enQuad:
                    case Charas.emQuad:
                    case Charas.enSpace:
                    case Charas.emSpace:
                    case Charas.threePerEmSpace:
                    case Charas.fourPerEmSpace:
                    case Charas.sixPerEmSpace:
                    case Charas.figureSpace:
                    case Charas.punctuationSpace:
                    case Charas.thinSpace:
                    case Charas.hairSpace:
                    case Charas.zeroWidthSpace:
                    case Charas.narrowNoBreakSpace:
                    case Charas.mathematicalSpace:
                    case Charas.ideographicSpace:
                    case Charas.byteOrderMark:
                        if (skipTrivia) {
                            pos++;
                            continue;
                        }
                        else {
                            while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) {
                                pos++;
                            }
                            return token = SyntaxKind.WhitespaceTrivia;
                        }
                    case Charas.exclamation:
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.ExclamationEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.ExclamationToken;
                    case Charas.doubleQuote:
                        tokenValue = scanString();
                        if (text.charCodeAt(pos) === Charas.c) {
                            tokenFlags |= TokenFlags.后缀c_;
                            pos++;
                        }
                        else if (text.charCodeAt(pos) === Charas.w) {
                            tokenFlags |= TokenFlags.后缀w_;
                            pos++;
                        }
                        return token = SyntaxKind.StringLiteral;
                    case Charas.singleQuote:
                        tokenValue = scanString();
                        if (text.charCodeAt(pos) === Charas.c) {
                            tokenFlags |= TokenFlags.后缀c_;
                            pos++;
                        }
                        else if (text.charCodeAt(pos) === Charas.w) {
                            tokenFlags |= TokenFlags.后缀w_;
                            pos++;
                        }
                        return token = SyntaxKind.字符字面量_;
                    case Charas.backtick:
                        token = scanTemplateAndSetTokenValue();
                        if (text.charCodeAt(pos) === Charas.c) {
                            tokenFlags |= TokenFlags.后缀c_;
                            pos++;
                        }
                        else if (text.charCodeAt(pos) === Charas.w) {
                            tokenFlags |= TokenFlags.后缀w_;
                            pos++;
                        }
                        return token;
                    case Charas.percent:
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.PercentEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.PercentToken;
                    case Charas.ampersand:
                        if (text.charCodeAt(pos + 1) === Charas.ampersand) {
                            return pos += 2, token = SyntaxKind.AmpersandAmpersandToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.AmpersandEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.AmpersandToken;
                    case Charas.openParen:
                        pos++;
                        return token = SyntaxKind.OpenParenToken;
                    case Charas.closeParen:
                        pos++;
                        return token = SyntaxKind.CloseParenToken;
                    case Charas.asterisk:
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.AsteriskEqualsToken;
                        }
                        pos++;
                        if (inJSDocType && !asteriskSeen && (tokenFlags & TokenFlags.PrecedingLineBreak)) {
                            // decoration at the start of a JSDoc comment line
                            asteriskSeen = true;
                            continue;
                        }
                        return token = SyntaxKind.AsteriskToken;
                    case Charas.plus:
                        if (text.charCodeAt(pos + 1) === Charas.plus) {
                            return pos += 2, token = SyntaxKind.PlusPlusToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.PlusEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.PlusToken;
                    case Charas.comma:
                        pos++;
                        return token = SyntaxKind.CommaToken;
                    case Charas.minus:
                        if (text.charCodeAt(pos + 1) === Charas.minus) {
                            return pos += 2, token = SyntaxKind.MinusMinusToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.MinusEqualsToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.greaterThan) {
                            // ->
                            return pos += 2, token = SyntaxKind.MinusGreaterThanToken;
                        }
                        pos++;
                        return token = SyntaxKind.MinusToken;
                    case Charas.中点_:
                        pos++;
                        return token = SyntaxKind.中点号_;
                    case Charas.dot:
                        if (isDigit(text.charCodeAt(pos + 1))) {
                            tokenValue = scanNumber().value;
                            return token = SyntaxKind.NumericLiteral;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.openBracket) {
                            return pos += 2, token = SyntaxKind.DotOpenBracketToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.lessThan) {
                            return pos += 2, token = SyntaxKind.点左尖号_;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.openParen) {
                            return pos += 2, token = SyntaxKind.点左括号_;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.dot && text.charCodeAt(pos + 2) === Charas.dot) {
                            return pos += 3, token = SyntaxKind.DotDotDotToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.dot) {
                            return pos += 2, token = SyntaxKind.DotDotToken;
                        }
                        pos++;
                        return token = SyntaxKind.DotToken;
                    case Charas.slash:
                        // Single-line comment
                        if(text.charCodeAt(pos + 1) === Charas.slash && text.charCodeAt(pos + 2) === Charas.at){
                            tokenFlags |= TokenFlags.编译转换词典_;
                        }
                        if(text.charCodeAt(pos + 1) === Charas.slash && text.charCodeAt(pos + 2) === Charas.hash){
                            tokenFlags |= TokenFlags.编译转换词典_;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.slash) {
                            pos += 2;

                            while (pos < end) {
                                if (isLineBreak(text.charCodeAt(pos))) {
                                    break;
                                }
                                pos++;

                            }

                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                return token = SyntaxKind.SingleLineCommentTrivia;
                            }
                        }
                        // Multi-line comment
                        if (text.charCodeAt(pos + 1) === Charas.asterisk) {
                            pos += 2;
                            if (text.charCodeAt(pos) === Charas.asterisk && text.charCodeAt(pos + 1) !== Charas.slash) {
                                tokenFlags |= TokenFlags.PrecedingJSDocComment;
                            }

                            let commentClosed = false;
                            while (pos < end) {
                                const ch = text.charCodeAt(pos);

                                if (ch === Charas.asterisk && text.charCodeAt(pos + 1) === Charas.slash) {
                                    pos += 2;
                                    commentClosed = true;
                                    break;
                                }

                                if (isLineBreak(ch)) {
                                    tokenFlags |= TokenFlags.PrecedingLineBreak;
                                }
                                pos++;
                            }

                            if (!commentClosed) {
                                error(Diagnostics.Asterisk_Slash_expected);
                            }

                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                if (!commentClosed) {
                                    tokenFlags |= TokenFlags.Unterminated;
                                }
                                return token = SyntaxKind.MultiLineCommentTrivia;
                            }
                        }

                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.SlashEqualsToken;
                        }

                        pos++;
                        return token = SyntaxKind.SlashToken;

                    case Charas._0:
                        if (pos + 2 < end && (text.charCodeAt(pos + 1) === Charas.X || text.charCodeAt(pos + 1) === Charas.x)) {
                            pos += 2;
                            tokenValue = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ true);
                            if (!tokenValue) {
                                error(Diagnostics.Hexadecimal_digit_expected);
                                tokenValue = "0";
                            }
                            tokenValue = "0x" + tokenValue;
                            tokenFlags |= TokenFlags.HexSpecifier;
                            return token = checkBigIntSuffix();
                        }
                        else if (pos + 2 < end && (text.charCodeAt(pos + 1) === Charas.B || text.charCodeAt(pos + 1) === Charas.b)) {
                            pos += 2;
                            tokenValue = scanBinaryOrOctalDigits(/* base */ 2);
                            if (!tokenValue) {
                                error(Diagnostics.Binary_digit_expected);
                                tokenValue = "0";
                            }
                            tokenValue = "0b" + tokenValue;
                            tokenFlags |= TokenFlags.BinarySpecifier;
                            return token = checkBigIntSuffix();
                        }
                        else if (pos + 2 < end && (text.charCodeAt(pos + 1) === Charas.O || text.charCodeAt(pos + 1) === Charas.o)) {
                            pos += 2;
                            tokenValue = scanBinaryOrOctalDigits(/* base */ 8);
                            if (!tokenValue) {
                                error(Diagnostics.Octal_digit_expected);
                                tokenValue = "0";
                            }
                            tokenValue = "0o" + tokenValue;
                            tokenFlags |= TokenFlags.OctalSpecifier;
                            return token = checkBigIntSuffix();
                        }
                        // Try to parse as an octal
                        if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
                            tokenValue = "" + scanOctalDigits();
                            tokenFlags |= TokenFlags.Octal;
                            return token = SyntaxKind.NumericLiteral;
                        }
                    // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
                    // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
                    // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
                    // falls through
                    case Charas._1:
                    case Charas._2:
                    case Charas._3:
                    case Charas._4:
                    case Charas._5:
                    case Charas._6:
                    case Charas._7:
                    case Charas._8:
                    case Charas._9:
                        ({ type: token, value: tokenValue } = scanNumber());
                        return token;
                    case Charas.colon:
                        if (text.charCodeAt(pos + 1) === Charas.greaterThan) {
                            return pos += 2, token = SyntaxKind.ColonGreaterThanToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.ColonEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.ColonToken;
                    case Charas.semicolon:
                        pos++;
                        return token = SyntaxKind.SemicolonToken;
                    case Charas.lessThan:
                        if (isConflictMarkerTrivia(text, pos)) {
                            pos = scanConflictMarkerTrivia(text, pos, error);
                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                return token = SyntaxKind.ConflictMarkerTrivia;
                            }
                        }

                        if (text.charCodeAt(pos + 1) === Charas.lessThan) {
                            if (text.charCodeAt(pos + 2) === Charas.equals) {
                                return pos += 3, token = SyntaxKind.LessThanLessThanEqualsToken;
                            }
                            return pos += 2, token = SyntaxKind.LessThanLessThanToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.LessThanEqualsToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.minus) {
                            return pos += 2, token = SyntaxKind.LessThanMinusToken
                        }
                        pos++;
                        return token = SyntaxKind.LessThanToken;
                    case Charas.equals:
                        if (isConflictMarkerTrivia(text, pos)) {
                            pos = scanConflictMarkerTrivia(text, pos, error);
                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                return token = SyntaxKind.ConflictMarkerTrivia;
                            }
                        }

                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.EqualsEqualsToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.greaterThan) {
                            return pos += 2, token = SyntaxKind.EqualsGreaterThanToken;
                        }
                        pos++;
                        return token = SyntaxKind.EqualsToken;
                    case Charas.greaterThan:
                        if (isConflictMarkerTrivia(text, pos)) {
                            pos = scanConflictMarkerTrivia(text, pos, error);
                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                return token = SyntaxKind.ConflictMarkerTrivia;
                            }
                        }

                        pos++;
                        return token = SyntaxKind.GreaterThanToken;
                    case Charas.question:
                        pos++;
                        if (text.charCodeAt(pos) === Charas.dot && !isDigit(text.charCodeAt(pos + 1))) {
                            pos++;
                            return token = SyntaxKind.QuestionDotToken;
                        }
                        return token = SyntaxKind.QuestionToken;
                    case Charas.openBracket:
                        pos++;
                        return token = SyntaxKind.OpenBracketToken;
                    case Charas.closeBracket:
                        pos++;
                        return token = SyntaxKind.CloseBracketToken;
                    case Charas.caret:
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.CaretEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.CaretToken;
                    case Charas.openBrace:
                        pos++;
                        return token = SyntaxKind.OpenBraceToken;
                    case Charas.bar:
                        if (isConflictMarkerTrivia(text, pos)) {
                            pos = scanConflictMarkerTrivia(text, pos, error);
                            if (skipTrivia) {
                                continue;
                            }
                            else {
                                return token = SyntaxKind.ConflictMarkerTrivia;
                            }
                        }

                        if (text.charCodeAt(pos + 1) === Charas.bar) {
                            return pos += 2, token = SyntaxKind.BarBarToken;
                        }
                        if (text.charCodeAt(pos + 1) === Charas.equals) {
                            return pos += 2, token = SyntaxKind.BarEqualsToken;
                        }
                        pos++;
                        return token = SyntaxKind.BarToken;
                    case Charas.closeBrace:
                        pos++;
                        return token = SyntaxKind.CloseBraceToken;
                    case Charas.tilde:
                        pos++;
                        return token = SyntaxKind.TildeToken;
                    case Charas.at:
                        pos++;
                        return token = SyntaxKind.AtToken;
                    case Charas.backslash:
                        const extendedCookedChar = peekExtendedUnicodeEscape();
                        if (extendedCookedChar >= 0 && isIdentifierStart(extendedCookedChar)) {
                            pos += 3;
                            tokenFlags |= TokenFlags.ExtendedUnicodeEscape;
                            tokenValue = scanExtendedUnicodeEscape() + scanIdentifierParts();
                            return token = getIdentifierToken();
                        }

                        const cookedChar = peekUnicodeEscape();
                        if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
                            pos += 6;
                            tokenFlags |= TokenFlags.UnicodeEscape;
                            tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
                            return token = getIdentifierToken();
                        }

                        error(Diagnostics.Invalid_character);
                        pos++;
                        return token = SyntaxKind.Unknown;
                    default:
                        if (isIdentifierStart(ch)) {
                            pos += charSize(ch);
                            while (pos < end && isIdentifierPart(ch = codePointAt(text, pos))) pos += charSize(ch);
                            tokenValue = text.substring(tokenPos, pos);
                            if (ch === Charas.backslash) {
                                tokenValue += scanIdentifierParts();
                            }
                            return token = getIdentifierToken();
                        }
                        else if (isWhiteSpaceSingleLine(ch)) {
                            pos += charSize(ch);
                            continue;
                        }
                        else if (isLineBreak(ch)) {
                            tokenFlags |= TokenFlags.PrecedingLineBreak;
                            pos += charSize(ch);
                            continue;
                        }
                        error(Diagnostics.Invalid_character);
                        pos += charSize(ch);
                        return token = SyntaxKind.Unknown;
                }
            }
        }

        function reScanGreaterToken(): SyntaxKind {
            if (token === SyntaxKind.GreaterThanToken) {
                if (text.charCodeAt(pos) === Charas.greaterThan) {
                    if (text.charCodeAt(pos + 1) === Charas.equals) {
                        return pos += 2, token = SyntaxKind.GreaterThanGreaterThanEqualsToken;
                    }
                    pos++;
                    return token = SyntaxKind.GreaterThanGreaterThanToken;
                }
                if (text.charCodeAt(pos) === Charas.equals) {
                    pos++;
                    return token = SyntaxKind.GreaterThanEqualsToken;
                }
            }
            return token;
        }

        function reScanSlashToken(): SyntaxKind {
            if (token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) {
                let p = tokenPos + 1;
                let inEscape = false;
                let inCharacterClass = false;
                while (true) {
                    // If we reach the end of a file, or hit a newline, then this is an unterminated
                    // regex.  Report error and return what we have so far.
                    if (p >= end) {
                        tokenFlags |= TokenFlags.Unterminated;
                        error(Diagnostics.Unterminated_regular_expression_literal);
                        break;
                    }

                    const ch = text.charCodeAt(p);
                    if (isLineBreak(ch)) {
                        tokenFlags |= TokenFlags.Unterminated;
                        error(Diagnostics.Unterminated_regular_expression_literal);
                        break;
                    }

                    if (inEscape) {
                        // Parsing an escape character;
                        // reset the flag and just advance to the next char.
                        inEscape = false;
                    }
                    else if (ch === Charas.slash && !inCharacterClass) {
                        // A slash within a character class is permissible,
                        // but in general it signals the end of the regexp literal.
                        p++;
                        break;
                    }
                    else if (ch === Charas.openBracket) {
                        inCharacterClass = true;
                    }
                    else if (ch === Charas.backslash) {
                        inEscape = true;
                    }
                    else if (ch === Charas.closeBracket) {
                        inCharacterClass = false;
                    }
                    p++;
                }

                while (p < end && isIdentifierPart(text.charCodeAt(p))) {
                    p++;
                }
                pos = p;
                tokenValue = text.substring(tokenPos, pos);
                token = SyntaxKind.RegularExpressionLiteral;
            }
            return token;
        }

        /**
         * Unconditionally back up and scan a template expression portion.
         */
        function reScanTemplateToken(): SyntaxKind {
            Debug.assert(token === SyntaxKind.CloseBraceToken, "'reScanTemplateToken' should only be called on a '}'");
            pos = tokenPos;
            token = scanTemplateAndSetTokenValue();
            if (text.charCodeAt(pos) === Charas.c) {
                tokenFlags |= TokenFlags.后缀c_;
                pos++;
            }
            else if (text.charCodeAt(pos) === Charas.w) {
                tokenFlags |= TokenFlags.后缀w_;
                pos++;
            }
            return token;
        }

        function reScanLessThanToken(): SyntaxKind {
            if (token === SyntaxKind.LessThanLessThanToken) {
                pos = tokenPos + 1;
                return token = SyntaxKind.LessThanToken;
            }
            return token;
        }

        function 扫描词典语句令牌(): 转换词典语句令牌_ {
            startPos = tokenPos = pos;
            tokenFlags = TokenFlags.None;
            if (pos >= end) {
                return token = SyntaxKind.EndOfFileToken;
            }
            while(true){
                const ch = codePointAt(text, pos);
                pos += charSize(ch);
                switch (ch) {
                    case Charas.at:
                        return token = SyntaxKind.AtToken;
                    case Charas.openBrace:
                        return token = SyntaxKind.OpenBraceToken;
                    case Charas.closeBrace:
                        return token = SyntaxKind.CloseBraceToken;
                    case Charas.comma:
                        return token = SyntaxKind.CommaToken;
                    case Charas.colon:
                        return token = SyntaxKind.ColonToken;
                    case Charas.hash:
                        return token = SyntaxKind.井号令牌_
                    case Charas.doubleQuote:
                        tokenValue = scanString();
                        return token = SyntaxKind.StringLiteral;
                }
                if (isIdentifierStart(ch)) {
                    let char = ch;
                    while (pos < end && isIdentifierPart(char = codePointAt(text, pos))) pos += charSize(char);
                    tokenValue = text.substring(tokenPos, pos);
                    return token = SyntaxKind.Identifier
                }
                startPos++;
                tokenPos++;
            }
        }

        function scanJsDocToken(): JSDocSyntaxKind {
            startPos = tokenPos = pos;
            tokenFlags = TokenFlags.None;
            if (pos >= end) {
                return token = SyntaxKind.EndOfFileToken;
            }

            const ch = codePointAt(text, pos);
            pos += charSize(ch);
            switch (ch) {
                case Charas.tab:
                case Charas.verticalTab:
                case Charas.formFeed:
                case Charas.space:
                    while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) {
                        pos++;
                    }
                    return token = SyntaxKind.WhitespaceTrivia;
                case Charas.at:
                    return token = SyntaxKind.AtToken;
                case Charas.lineFeed:
                case Charas.carriageReturn:
                    tokenFlags |= TokenFlags.PrecedingLineBreak;
                    return token = SyntaxKind.NewLineTrivia;
                case Charas.openBrace:
                    return token = SyntaxKind.OpenBraceToken;
                case Charas.closeBrace:
                    return token = SyntaxKind.CloseBraceToken;
                case Charas.openBracket:
                    return token = SyntaxKind.OpenBracketToken;
                case Charas.closeBracket:
                    return token = SyntaxKind.CloseBracketToken;
                case Charas.lessThan:
                    return token = SyntaxKind.LessThanToken;
                case Charas.greaterThan:
                    return token = SyntaxKind.GreaterThanToken;
                case Charas.equals:
                    return token = SyntaxKind.EqualsToken;
                case Charas.comma:
                    return token = SyntaxKind.CommaToken;
                case Charas.dot:
                    return token = SyntaxKind.DotToken;
                case Charas.backtick:
                    return token = SyntaxKind.BacktickToken;
                case Charas.backslash:
                    pos--;
                    const extendedCookedChar = peekExtendedUnicodeEscape();
                    if (extendedCookedChar >= 0 && isIdentifierStart(extendedCookedChar)) {
                        pos += 3;
                        tokenFlags |= TokenFlags.ExtendedUnicodeEscape;
                        tokenValue = scanExtendedUnicodeEscape() + scanIdentifierParts();
                        return token = getIdentifierToken();
                    }

                    const cookedChar = peekUnicodeEscape();
                    if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
                        pos += 6;
                        tokenFlags |= TokenFlags.UnicodeEscape;
                        tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
                        return token = getIdentifierToken();
                    }
                    pos++;
                    return token = SyntaxKind.Unknown;
            }

            if (isIdentifierStart(ch)) {
                let char = ch;
                while (pos < end && isIdentifierPart(char = codePointAt(text, pos)) || text.charCodeAt(pos) === Charas.minus) pos += charSize(char);
                tokenValue = text.substring(tokenPos, pos);
                if (char === Charas.backslash) {
                    tokenValue += scanIdentifierParts();
                }
                return token = getIdentifierToken();
            }
            else {
                return token = SyntaxKind.Unknown;
            }
        }

        function speculationHelper<T>(callback: () => T, isLookahead: boolean): T {
            const savePos = pos;
            const saveStartPos = startPos;
            const saveTokenPos = tokenPos;
            const saveToken = token;
            const saveTokenValue = tokenValue;
            const saveTokenFlags = tokenFlags;
            const result = callback();

            // If our callback returned something 'falsy' or we're just looking ahead,
            // then unconditionally restore us to where we were.
            if (!result || isLookahead) {
                pos = savePos;
                startPos = saveStartPos;
                tokenPos = saveTokenPos;
                token = saveToken;
                tokenValue = saveTokenValue;
                tokenFlags = saveTokenFlags;
            }
            return result;
        }

        function scanRange<T>(start: number, length: number, callback: () => T): T {
            const saveEnd = end;
            const savePos = pos;
            const saveStartPos = startPos;
            const saveTokenPos = tokenPos;
            const saveToken = token;
            const saveTokenValue = tokenValue;
            const saveTokenFlags = tokenFlags;

            setText(text, start, length);
            const result = callback();

            end = saveEnd;
            pos = savePos;
            startPos = saveStartPos;
            tokenPos = saveTokenPos;
            token = saveToken;
            tokenValue = saveTokenValue;
            tokenFlags = saveTokenFlags;

            return result;
        }

        function lookAhead<T>(callback: () => T): T {
            return speculationHelper(callback, /*isLookahead*/ true);
        }

        function tryScan<T>(callback: () => T): T {
            return speculationHelper(callback, /*isLookahead*/ false);
        }

        function getText(): string {
            return text;
        }

        function setText(newText: string | undefined, start: number | undefined, length: number | undefined) {
            text = newText || "";
            end = length === undefined ? text.length : start! + length;
            setTextPos(start || 0);
        }

        function setOnError(errorCallback: ErrorCallback | undefined) {
            onError = errorCallback;
        }

        function setTextPos(textPos: number) {
            Debug.assert(textPos >= 0);
            pos = textPos;
            startPos = textPos;
            tokenPos = textPos;
            token = SyntaxKind.Unknown;
            tokenValue = undefined!;
            tokenFlags = TokenFlags.None;
        }

        function setInJSDocType(inType: boolean) {
            inJSDocType += inType ? 1 : -1;
        }
    }

    /* @internal */
    const codePointAt: (s: string, i: number) => number = (String.prototype as any).codePointAt ? (s, i) => (s as any).codePointAt(i) : function codePointAt(str, i): number {
        // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
        const size = str.length;
        // Account for out-of-bounds indices:
        if (i < 0 || i >= size) {
            return undefined!; // String.codePointAt returns `undefined` for OOB indexes
        }
        // Get the first code unit
        const first = str.charCodeAt(i);
        // check if it’s the start of a surrogate pair
        if (first >= 0xD800 && first <= 0xDBFF && size > i + 1) { // high surrogate and there is a next code unit
            const second = str.charCodeAt(i + 1);
            if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
                // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
                return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
            }
        }
        return first;
    };

    /* @internal */
    function charSize(ch: number) {
        if (ch >= 0x10000) {
            return 2;
        }
        return 1;
    }
}
